package com.csdj.controller;


import com.csdj.entity.User;
import com.csdj.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


import javax.annotation.Resource;
import java.util.List;

@Controller
public class UserController {
    @Resource
    private IUserService userSerivce;
    @GetMapping("info")
    public String allInfo(@RequestParam(required=true,defaultValue="1") Integer page, Model model) {
        PageHelper.startPage(page, 5);
        //查询
        List<User> users = userSerivce.findAllInfo();
        //创建PageInfo对象，保存查询出的结果，PageInfo是pageHelper中的对象
        PageInfo<User> p=new PageInfo<>(users);
        model.addAttribute("users",users);
        model.addAttribute("p",p);
        return "index";
    }
}
